//	ID : pallab81
// 	PROG : 11703
// 	LANG : C++
// 	2011-08-31-15.08.29 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define pi 3.14159265

const int inf = (int)1e6;
Int memo[inf+10];

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}

inline Int go(int i){
    if( i==0 ){
        return 1LL;
    }
    Int &res = memo[i];
    if(res!=-1){
        return res;
    }
    res=0;
    res+=go( (int)floor( i- sqrt( i ) ) );
    res+=go( (int)floor( log( i ) ) );
    res+=go((int)floor( i*sin( i )*sin( i )  ) );
    res%=inf;
return res;
}
inline void Proc(int N){
    printf("%lld\n",go(N));
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif
    SET(memo,-1);
    go(inf);

    int N;
    while( scanf("%d",&N)==1 ){
        if( N==-1 )break;
        Proc(N);
    }

return 0;
}
